﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Configuration;

namespace VisualWebGuiApplication2
{
    public partial class report1 : System.Web.UI.Page
    {
        int tankid = 0;
        string DatetimeFormat = ConfigurationManager.AppSettings["DatetimeFormat"];
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (null != Request.QueryString["id"])
                {
                    tankid = Convert.ToInt32(Request.QueryString["id"].ToString());
                  
                    renderrep(tankid);
                }
            }
        }

        public void renderrep(int tankid)
        {
            using (GazOnDevEntities db =new GazOnDevEntities())
            {
               
                var query = db.Tank_Stocks.FirstOrDefault(x => x.Id == tankid);
                var query1 = from i in db.Tank_Stocks
                             where i.Id == tankid
                             select i;
                List<Tank_Stocks> dd = query1.ToList<Tank_Stocks>();
                dd.FirstOrDefault().Datetime = dd.FirstOrDefault().Datetime;
                dd.FirstOrDefault().Date_of_Fix = dd.FirstOrDefault().Date_of_Fix;
               //if(dd.FirstOrDefault().type =="0")
               //{
               //    dd.FirstOrDefault().type = "תת קרקעי";
               // }else
               //    {
               //        dd.FirstOrDefault().type = "עילי";
                   
                   
               //    }


               if (dd.FirstOrDefault().type == "0")
               {
                   dd.FirstOrDefault().type = "קרקעי";
               }
               if (dd.FirstOrDefault().type == "1")
               {
                   dd.FirstOrDefault().type = "עילי";
               }
               if (dd.FirstOrDefault().type == "2")
               {
                   dd.FirstOrDefault().type = "עילי עובר לתת";



               }
               if (dd.FirstOrDefault().type == "3")
               {
                   dd.FirstOrDefault().type = "שינויים";
               }
  
                 this.reportViewer1.LocalReport.DataSources.Clear();
                 this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dd));

                 this.reportViewer1.ShowPrintButton = true;

          
          
                this.reportViewer1.DataBind();
                reportViewer1.LocalReport.Refresh();
              //  this.reportViewer1.Reset();

           //     this.reportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
                 //ReportDataSource rds = new ReportDataSource("DataSet1",AllFamilies.GetAllProjects);
                 //this.reportViewer1.LocalReport.DataSources = AllFamilies.GetAllProjects;
                

                
            }

            /* DataSet Data = new DataSet();
               Data.ReadXml(this.Context.Server.MapPath(ReportPath + "data.xml"));*/

            //if (MSMODE.Checked)
            //{
            //    Report.Render(Reporting.ReportViewer.RenderType.MSReportViewer, ReportPath, ReportName, ReportName, new ReportDataSource("Sales", Data.Tables[0]));
            //    MessageBox.Show("MS ReportViewer 2010 VWG support is broken -> IFrame Bug, Scriptmanager");
            //}
            //else
            //{
            //  Report.Render(Reporting.ReportViewer.RenderType.PDFReportViewer, ReportPath, ReportName, ReportName, new ReportDataSource("Sales", Data.Tables[0]));
            //}

            // this.Report..LocalReport.DataSources.Clear();
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetMoslemFamily", ListFamilyMoslemproj));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetFoodBox", ListFoodBoxmproj));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetPerson", ListPerson));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetHomeFix", ListHomeFix));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetSchoolBags", ListSchoolBags));

            //this.reportViewer1.Reset();

            //this.reportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
            // ReportDataSource rds = new ReportDataSource("DataSet1",AllFamilies.GetAllProjects);
            // this.reportViewer1.LocalReport.DataSources = AllFamilies.GetAllProjects;

            //this.reportViewer1.DataBind(); 
            // reportmoslemFamilyProjectBindingSource.DataSource = AllFamilies.GetAllProjects; 
            // Below code demonstrate the Parameter passing method. Use only if you have parameters into the reports.


            //ReportParameter p1 = new ReportParameter("FullName", currentPerson.FirstName + " " + currentPerson.FatherName + " " + currentPerson.LastName);
            //ReportParameter p2 = new ReportParameter("PersonID", currentPerson.IDnum);

            //reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2 });
            //reportViewer1.Visible = true;

        }
    }
}